define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'mental/remark/index' + location.search,
                    add_url: 'mental/remark/add',
                    edit_url: 'mental/remark/edit',
                    del_url: 'mental/remark/del',
                    multi_url: 'mental/remark/multi',
                    table: 'mental_remark',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        { checkbox: true },
                        { field: 'id', title: __('Id') },
                        { field: 'user_id', title: __('User_id') },
                        { field: 'title', title: __('Main_id') },
                        { field: 'content', title: __('Content') },
                        { field: 'is_audit', title: __('Is_audit'), searchList: { "0": __('Is_audit 0'), "1": __('Is_audit 1') }, formatter: Table.api.formatter.status },
                        { field: 'createtime', title: __('Createtime'), operate: 'RANGE', addclass: 'datetimerange', formatter: Table.api.formatter.datetime },
                        {
                            field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate, buttons: [
                                {
                                    name: 'audit',
                                    text: __('Is_audit'),
                                    title: __('Is_audit'),
                                    classname: 'btn btn-xs btn-success btn-magic btn-ajax',
                                    url: 'mental/remark/audit',
                                    confirm: __('Confirm to submit?'),
                                    success: function (data, ret) {
                                        table.bootstrapTable('refresh');
                                        Toastr.success(ret.msg);
                                        return false;
                                    },
                                    error: function (data, ret) {
                                        Toastr.error(ret.msg);
                                        return false;
                                    },
                                    hidden: function (row) {
                                        if (row.is_audit) {
                                            return true;
                                        }
                                        return false;
                                    }
                                }]
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});